#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T;
ll n;
ll a[200005];
ll col[200005];
ll ans=0;
void Dfs(ll deep) {
    if(deep>n) {
        return ;
    }
    else if(deep==n) {
        ll sum=0;
        for(ll i=1; i<=n; i++) {
            for(ll j=i-1; j>=1; j--) {
                if(col[i]==col[j]) {
                    if(a[i]==a[j]) {
                        sum+=a[i];
                    }
                    break;
                }
            }
        }
        ans=((ans<sum)?sum:ans);
        return ;
    }
    else {
        col[deep+1]=1;
        Dfs(deep+1);
        col[deep+1]=2;
        Dfs(deep+1);
        col[deep+1]=0;
        return ;
    }
    return ;
}
int main () {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    for(ll t=1; t<=T; t++) {
        cin >> n;
        for(ll i=1; i<=n; i++) {
            cin >> a[i];
        }
        ans=0;
        memset(col, 0, sizeof(col));
        col[1]=1;
        Dfs(1);
        col[1]=2;
        Dfs(1);
        col[1]=0;
        cout << ans << endl;
    }
    return 0;
}
